import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
import javafx.scene.control.Button;

public class TaskThreadDemo extends Application{
    TextArea textArea;
    FlowPane pane;
    Scene scene;
    Stage s0;
    @Override
    public void start(Stage primaryStage){
        s0 = primaryStage;
        textArea = new TextArea();
        textArea.setWrapText(true);
        Button b = new Button("开始");
        pane = new FlowPane();
        pane.setAlignment(Pos.CENTER);
        pane.setPadding(new Insets(10));
        pane.setVgap(10);
        pane.getChildren().addAll(textArea,b);
        scene = new Scene(pane);
        b.setOnAction(e -> Do());
        primaryStage.setScene(scene);
        primaryStage.setTitle("多线程示例");
        primaryStage.show();

    }
    public static void main(String[] args){
        launch(args);
    }
    private void Do(){
        Stage s1 = new Stage();
        s1.setScene(scene);
        s1.show();
        s0.close();

    }
    private void Test(){
        textArea.setText(pane.getChildren()+"");
    }
    private void DoSome(){
        Runnable PrintA = new PrintChar('A',1000,textArea);
        Runnable PrintB = new PrintChar('B',1000,textArea);
        Runnable Print100 = new PrintNum<Integer>(100,1000,textArea);

        Thread t1 = new Thread(PrintA);
        Thread t2 = new Thread(PrintB);
        Thread t3 = new Thread(Print100);

        t1.start();
        t2.start();
        t3.start();
    }
}
class PrintChar implements Runnable{
    private char charToPrint;
    private int times;
    private TextArea Text;
    public PrintChar(char charToPrint,int times, TextArea Text){
        this.charToPrint = charToPrint;
        this.times = times;
        this.Text = Text;
    }
    @Override
    public void run() {
        for (int i = 0; i < times; i++) {
            Text.appendText(""+charToPrint);
        }
    }
}
class PrintNum<T extends Number> implements Runnable{
    private T NumToPrint;
    private int times;
    private TextArea Text;
    public PrintNum(T numToPrint,int times,TextArea Text){
        this.NumToPrint = numToPrint;
        this.times = times;
        this.Text = Text;
    }
    @Override
    public void run(){
        for(int i = 0; i < times; i++){
            Text.appendText(""+NumToPrint);
        }
    }
}